package com.microstation.service.impl;
import java.util.List;

import com.microstation.enums.ResultEnum;
import com.microstation.exception.ElementEmptyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.microstation.service.SmsInfoService;
import com.microstation.dao.SmsInfoDao;
import com.microstation.common.Assist;
import com.microstation.common.Result;
import com.microstation.entity.po.SmsInfo;
/**
 * SmsInfo的服务接口的实现类
 * 
 * @author 
 *
 */
@Service
public class SmsInfoServiceImpl implements SmsInfoService {
	private final Logger LOG = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private SmsInfoDao smsInfoDao;

	@Override
	public Result find(Assist assist) {
		//TODO这里可以做通过Assist做添加查询
		long results = smsInfoDao.getSmsInfoRowCount(assist);
		List<SmsInfo> result = smsInfoDao.selectSmsInfo(assist);
		return new Result(results, result);
	}
	@Override
	public SmsInfo findOne(Long id) {
		if (id == null) {
			return null;
		}
		SmsInfo result = smsInfoDao.selectSmsInfoById(id);
		return result;
	}

	@Override
	public Integer saveNotNull(SmsInfo value) {
		if (value == null) {
			return null;
		}
		if(value.getType() == null || value.getMobile() == null || value.getCode() == null || value.getValidtime() == null || value.getIp() == null  ){
        	throw new ElementEmptyException(ResultEnum.EMPTY.getInfo());
		}
		int result = smsInfoDao.insertNotNullSmsInfo(value);
		return result;
	}
	@Override
	public Integer updateNotNullById(SmsInfo value) {
		if (value == null) {
			return null;
		}
		int result = smsInfoDao.updateNotNullSmsInfoById(value);
		return result;
	}

	@Override
	public Integer deleteById(Long id) {
		if (id == null) {
			return null;
		}
		int result = smsInfoDao.deleteSmsInfoById(id);
		return result;
	}


}